package com.cskaoyan.service.impl;

import com.cskaoyan.bean.param.BaseWxParam;
import com.cskaoyan.bean.pojo.MarketIssue;
import com.cskaoyan.bean.pojo.MarketIssueExample;
import com.cskaoyan.bean.vo.IssueListVO;
import com.cskaoyan.mapper.MarketIssueMapper;
import com.cskaoyan.service.IssueListService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :LuoXuXin
 * @version : $version
 * @date :Created in 2022/4/12   10:07
 * @description:
 * @return:
 */
@Service
public class WxIssueListServiceImpl implements IssueListService {

    @Autowired
    MarketIssueMapper marketIssueMapper;

    @Override
    public IssueListVO issueList(BaseWxParam baseWxParam) {
        //分页
        Integer limit = baseWxParam.getLimit();
        Integer page = baseWxParam.getPage();
        PageHelper.startPage(page, limit);
        MarketIssueExample marketIssueExample = new MarketIssueExample();

        MarketIssueExample.Criteria criteria = marketIssueExample.createCriteria();

        List<MarketIssue> marketIssues =
                marketIssueMapper.selectByExample(marketIssueExample);
        PageInfo<MarketIssue> marketIssuePageInfo = new PageInfo<>(marketIssues);
        long total = marketIssuePageInfo.getTotal();
        int pages = marketIssuePageInfo.getPages();
        //构造返回参数
        IssueListVO issueListVO = new IssueListVO(total, pages, limit, page, marketIssues);


        return issueListVO;
    }
}
